<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /* 
            回调函数
                让if中的语句不会是死的
        */
        class Person {
        constructor(name, age) {
          this.name = name;
          this.age = age;
        }
      }
      const ArrPerson = [new Person('GG', 18), new Person('GG', 38), new Person('GG', 8)];
      function filter(arr) {

        const newArr = [];

        for (let i = 0; i < arr.length; i++) {
          if (fn(arr[i])) {
            newArr.push(arr[i]);
          }
        }
        return newArr
      }
      const fn = (a) => {
        return a.name === "GG"
      }
    //调用后,因为fn(arr[i])给a赋值,所以=arr[i].name
    // 返回true 或者 false
        // 调用函数 fn 吧
      const result = filter(ArrPerson,fn);
      console.log(result);


    </script>
</head>
<body>
    
</body>
</html>